package com.jiazhong.backend.controller;

import com.jiazhong.backend.service.BookService;
import com.jiazhong.commons.Util.JsonResult;
import com.jiazhong.commons.bean.Book;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/book")
public class BookController {
    @Resource
    private BookService service;

    @RequestMapping("/find")
    public JsonResult find(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value = "size",defaultValue = "10")int size){
        return service.find(page,size);
    }
    @RequestMapping("/search")
    public JsonResult findSearch(@RequestParam("name") String name, @RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value = "size",defaultValue = "10")int size){
        return service.findSearch(name, page, size);
    }

    @RequestMapping("/save")
    public JsonResult saveBook(Book book){
        return service.saveBook(book);
    }

    @RequestMapping("remove")
    public JsonResult removeBook(@RequestParam("id") String id){
        return service.removeBook(id);
    }

    @RequestMapping("/exists")
    public  JsonResult findExists(@RequestParam("colum") String colum,@RequestParam("value") String value){
        return service.findExists(colum, value);
    }


}
